package ModelLayer;

import java.util.ArrayList;

/**
 * 
 * @author Gruppe 2
 * 
 */
public class SalesOrder {
	private int orderNo;
	private String salesOrderDate;
	private String salesOrderStatus;
	private String deliveryDate;
	private int invoiceNo;
	private Customer c;
	private ArrayList<SalesLine> salesLineArray;

	/**
	 * 
	 * @param orderNo
	 * @param salesOrderDate
	 * @param salesOrderStatus
	 * @param deliveryDate
	 * @param invoiceNo
	 * @param c
	 */
	public SalesOrder(int orderNo, String salesOrderDate,
			String salesOrderStatus, String deliveryDate, int invoiceNo,
			Customer c) {
		this.orderNo = orderNo;
		this.salesOrderDate = salesOrderDate;
		this.salesOrderStatus = salesOrderStatus;
		this.deliveryDate = deliveryDate;
		this.invoiceNo = invoiceNo;
		this.c = c;
		salesLineArray = new ArrayList<SalesLine>();

	}

	public SalesOrder() {
		salesLineArray = new ArrayList<SalesLine>();
	}

	/**
	 * 
	 * @return salesLineArray
	 */
	public ArrayList<SalesLine> getSalesLineArray() {
		return salesLineArray;
	}

	/**
	 * 
	 * @param sl
	 */
	public void addSalesLine(SalesLine sl) {
		salesLineArray.add(sl);
	}

	/**
	 * 
	 * @return orderNo
	 */
	public int getOrderNo() {
		return orderNo;
	}

	/**
	 * 
	 * @param orderNo
	 */
	public void setOrderNo(int orderNo) {
		this.orderNo = orderNo;
	}

	/**
	 * 
	 * @return salesOrderDate
	 */
	public String getSalesOrderDate() {
		return salesOrderDate;
	}

	/**
	 * 
	 * @param salesOrderDate
	 */
	public void setSalesOrderDate(String salesOrderDate) {
		this.salesOrderDate = salesOrderDate;
	}

	/**
	 * 
	 * @return salesOrderStatus
	 */
	public String getSalesOrderStatus() {
		return salesOrderStatus;
	}

	/**
	 * 
	 * @param salesOrderStatus
	 */
	public void setSalesOrderStatus(String salesOrderStatus) {
		this.salesOrderStatus = salesOrderStatus;
	}

	/**
	 * 
	 * @return deliveryDate
	 */
	public String getDeliveryDate() {
		return deliveryDate;
	}

	/**
	 * 
	 * @param deliveryDate
	 */
	public void setDeliveryDate(String deliveryDate) {
		this.deliveryDate = deliveryDate;
	}

	/**
	 * 
	 * @return invoiceNo
	 */
	public int getInvoiceNo() {
		return invoiceNo;
	}

	/**
	 * 
	 * @param invoiceNo
	 */
	public void setInvoiceNo(int invoiceNo) {
		this.invoiceNo = invoiceNo;
	}

	/**
	 * 
	 * @return c
	 */
	public Customer getCustomer() {
		return c;
	}

	/**
	 * 
	 * @param c
	 */
	public void setCustomer(Customer c) {
		this.c = c;
	}

	/**
	 * 
	 * @return result
	 */
	public double calculateTotalSalesPrice() {
		double result = 0;
		for (SalesLine sl : salesLineArray) {
			result += sl.getProduct().getSalesPrice() * sl.getQuantity();
		}
		return result;
	}

	/**
	 * 
	 * @param product
	 * @return
	 */
	public boolean testExistingSalesLines(Product product) {
		boolean test = true;
		for (SalesLine salesLine : salesLineArray) {
			if (salesLine.getProduct() == product) {
				test = false;
			}
		}
		return test;

	}

	/**
	 * 
	 * @return
	 */
	public int getSalesLineId() {
		return salesLineArray.size() + 1;
	}

}
